/*
 * @Author: your name
 * @Date: 2021-03-07 19:04:41
 * @LastEditTime: 2021-03-07 21:11:44
 * @LastEditors: Please set LastEditors
 * @Description: isPalindrome
 * @FilePath: \relearnJS\algorithm\回文数字.js
 */
// 不断取两端数字进行比较
function f1(n) {
    if (n < 0) return false
    var ten = 10,
        tmp = n
    while (n / 10 >= 10) {
        ten *= 10
        n /= 10
    }
    var left, right
    while (tmp > 9) {
        left = parseInt(tmp / ten)
        right = tmp % 10
        while (left !== right) return false
        tmp %= ten
        tmp = parseInt(tmp / 10)
        ten /= 100
    }
    return true
}

// 将后半段数字翻转过来
function f4(n) {
    if (n < 0) return false
    var res = 0
    while (res < n) {
        res = res * 10 + n % 10
        n = parseInt(n / 10)
    }
    if (res === n || parseInt(res / 10) === n) return true
    return false
}

// 转成字符串1
function f2(s) {
    s += ''
    for (var left = 0, right = s.length - 1; left < right; left++, right--) {
        if (s[left] !== s[right]) return false
    }
    return true
}

// 转成字符串2
function f3(s) {
    s += ''
    return Array.from(s).reverse().join('') === s
}